﻿using Core.Configuration.Api;
using IconYuan.Manager.Products;
using IconYuan.Model.Entity.Products;
using Microsoft.AspNetCore.Mvc;
namespace IconYuan.Api.Controllers.Admin.Products
{
    public class CateController : AdminApi
    {
        CateManager cateSvc;
        public CateController()
        {
            cateSvc = new CateManager();
        }
        /// <summary>
        /// 分类列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object Index()
        {
            var list = new List<Cate>();
            list.Add(new Cate() { name = "分类名称" });
            return list;
        }

        /// <summary>
        /// 添加分类
        /// </summary>
        /// <param name="cate"></param>
        [HttpPost]
        public async Task<bool> Add([FromBody] Cate cate)
        {
            cate.store_id = store_id;
            cate.update_time = DateTime.Now;

            if (cate.category_id > 0)
                return await cateSvc.UpdateAsync(cate);
            else
            {
                cate.create_time = DateTime.Now;
                return await cateSvc.InsertAsync(cate) > 0;
            }
        }
        /// <summary>
        /// 删除分类
        /// </summary>
        /// <param name="cate"></param>
        /// <returns></returns>
        [HttpPost]
        public bool Delete([FromBody] Cate cate)
        {
            return cateSvc.Delete(cate.category_id);
        }
    }
}
